package com.rattsoftware.client.controllers;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.google.gwt.core.client.GWT;
import com.rattsoftware.client.AppMessages;
import com.rattsoftware.client.webclient;
import com.rattsoftware.client.events.AppEvents;
import com.rattsoftware.client.service.CourseServiceAsync;
import com.rattsoftware.client.service.CourseUnitServiceAsync;
import com.rattsoftware.client.service.UserServiceAsync;
import com.rattsoftware.client.views.NewEditCourseUnitView;

public class NewEditCourseUnitController extends Controller {

	AppMessages appMessages = GWT.create(AppMessages.class);

	private CourseServiceAsync courseService;
	private CourseUnitServiceAsync courseUnitService;
	private UserServiceAsync userService;
	private NewEditCourseUnitView newEditCourseUnitView;

	public NewEditCourseUnitController() {
		super();
		userService = Registry.get(webclient.USER_SERVICE);
		courseUnitService = Registry.get(webclient.COURSE_UNIT_SERVICE);
		courseService = Registry.get(webclient.COURSE_SERVICE);
		registerEventTypes(AppEvents.NewCourseUnit);
		registerEventTypes(AppEvents.EditCourseUnit);
	}
	
	public void initialize() {
		GWT.log("NewEditCourseUnitController : initialize");
		super.initialize();
		newEditCourseUnitView = new NewEditCourseUnitView(this);
	}

	@Override
	public void handleEvent(AppEvent event) {
		GWT.log("NewEditCourseUnitController : handleEvent");
		EventType type = (EventType) event.getType();
		if (type == AppEvents.NewCourseUnit) {
			forwardToView(newEditCourseUnitView, event);
		} else if (type == AppEvents.EditCourseUnit) {
			forwardToView(newEditCourseUnitView, event);
		}
	}
}
